<template>
  <div class="collect">
    <el-form :inline="true" label-width="80px" label-position="top">
      <el-form-item
        label="要班结的油站"
        prop="payType"
        v-if="!isStationAccount"
      >
        <span v-if="stationList.length == 1">{{
          stationList[0].stationName
        }}</span>
        <el-select
          v-else
          v-model="stationId"
          placeholder=""
          clearable
          style="width: 350px"
          size="small"
          @change="staionChange"
        >
          <el-option
            v-for="ele in stationList"
            :label="ele.stationName"
            :key="ele.stationId"
            :value="ele.stationId"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <el-row :gutter="20">
      <el-col :span="1.5" style="font-size: 15px">
        班结时间：<b>{{ lastBanjieTime }}</b>
        <span style="margin: 0px 10px">至</span> <b>{{ createEndTime }}</b>
      </el-col>
      <el-col :span="3" v-show="stationId">
        <el-button
          icon="el-icon-refresh"
          size="mini"
          type="primary"
          plain
          @click="staionChange(stationId)"
          :loading="updateTimeLoading"
        >
          更新班结结束时间
        </el-button>
      </el-col>
    </el-row>

    <div class="item">
      <div class="title">班结对账汇总</div>
      <div class="table">
        <el-table
          :show-header="false"
          :data="table1"
          border
          style="width: 100%; height: 100%"
          :cell-class-name="addclass"
        >
          <el-table-column prop="title1" label="数值 2">
            <template slot-scope="scope">
              <div style="width: 100%; height: 100%">
                {{ scope.row.title1 }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="amount1" label="数值 3"> </el-table-column>
          <el-table-column prop="title2" label="数值 2"> </el-table-column>
          <el-table-column prop="amount2" label="数值 3"> </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="item">
      <div class="title">消费-油品汇总</div>
      <div class="table">
        <el-table
          :data="queryGroupByOil"
          border
          style="width: 100%; height: 100%"
        >
          <el-table-column prop="oil_name" label="油品名"> </el-table-column>
          <el-table-column prop="oil_price" label="油价-原价">
          </el-table-column>
          <el-table-column prop="order_liters" label="加油数量(L/kg)">
          </el-table-column>
          <el-table-column prop="receivable_amt" label="应收(元)">
          </el-table-column>
          <el-table-column prop="amt" label="实收(元)"> </el-table-column>
          <el-table-column prop="discount_amt" label="立减优惠合计(元)">
          </el-table-column>
          <el-table-column prop="discount_coupon_amt" label="优惠券优惠合计(元)"></el-table-column>
          <el-table-column prop="bargain_discount_amt" label="议价优惠金额(元)"></el-table-column>
          <el-table-column prop="order_count" label="笔数"> </el-table-column>
          <!--<el-table-column prop="serviceCharge" label="手续费"> </el-table-column>-->
          <!-- <el-table-column prop="equipment_code" label="班结设备"> -->
          <!-- </el-table-column> -->
        </el-table>
      </div>
    </div>

    <div class="item">
      <div class="title">消费-油枪汇总</div>
      <div class="table">
        <el-table
          :data="queryGroupByOilGun"
          border
          style="width: 100%; height: 100%"
        >
          <el-table-column prop="oil_gun" label="油枪"> </el-table-column>
          <el-table-column prop="oil_name" label="油品名"> </el-table-column>
          <el-table-column prop="oil_price" label="油价-单价(元)">
          </el-table-column>
          <el-table-column prop="startFlowMeter" label="开始泵码" />
          <el-table-column prop="endFlowMeter" label="结束泵码" />
          <el-table-column prop="totalWordCount" label="走字数" />
          <el-table-column prop="order_liters" label="数量(L/kg)">
          </el-table-column>
          <!-- <el-table-column prop="amt" label="应收(元)"> </el-table-column> -->
        </el-table>
      </div>
    </div>

    <!-- <div class="item">
      <div class="title">消费-油枪汇总</div>
      <div class="table">
        <el-table
          :data="queryGroupByOilGun"
          border
          style="width: 100%; height: 100%"
        >
          <el-table-column prop="oil_gun" label="油枪"> </el-table-column>
          <el-table-column prop="oil_name" label="油品名"> </el-table-column>
          <el-table-column prop="oil_price" label="油价-单价(元)">
          </el-table-column>
          <el-table-column prop="order_liters" label="加油数量(L/kg)">
          </el-table-column>
          <el-table-column prop="receivable_amt" label="应收(元)">
          </el-table-column>
          <el-table-column prop="amt" label="实收(元)"> </el-table-column>
          <el-table-column prop="discount_amt" label="立减优惠合计(元)">
          </el-table-column>
          <el-table-column
            prop="discount_coupon_amt"
            label="优惠券优惠合计(元)"
          >
          </el-table-column>
          <el-table-column prop="serviceCharge" label="手续费"> </el-table-column>
        </el-table>
      </div>
    </div> -->

    <div class="item">
      <div class="title">消费-支付方式汇总</div>
      <div class="table">
        <el-table
          :data="queryGroupByPayType"
          border
          style="width: 100%; height: 100%"
        >
          <el-table-column
            prop="pay_type"
            label="支付方式"
            :formatter="formatterPayType"
          >
          </el-table-column>
          <el-table-column prop="amt" label="消费合计(元)"> </el-table-column>
          <el-table-column prop="refund_amt" label="退款合计(元)">
          </el-table-column>
          <el-table-column prop="discount_amt" label="立减优惠合计(元)">
          </el-table-column>
          <el-table-column prop="discount_coupon_amt" label="优惠券优惠合计(元)"></el-table-column>
          <el-table-column prop="bargain_discount_amt" label="议价优惠金额(元)"></el-table-column>
          <el-table-column prop="order_count" label="笔数">
            <template slot-scope="{row}">
              {{ row.order_count ? row.order_count : 0 }}
            </template>
          </el-table-column>

          <!--<el-table-column prop="serviceCharge" label="手续费"> </el-table-column>-->
          <!-- <el-table-column prop="sumPrice" label="加总合计"> </el-table-column> -->
        </el-table>
      </div>
    </div>

    <div class="item">
      <div class="title">消费-员工方式汇总</div>
      <div class="table">
        <el-table
          :data="queryGroupByEmployees"
          border
          style="width: 100%; height: 100%"
        >
          <el-table-column prop="oil_personnel_name" label="账号">
          </el-table-column>
          <!-- <el-table-column prop="oil_name" label="油品"> </el-table-column> -->
          <el-table-column prop="receivable_amt" label="应收(元)">
          </el-table-column>
          <el-table-column prop="amt" label="实收(元)"> </el-table-column>
          <el-table-column prop="discount_amt" label="立减优惠合计(元)">
          </el-table-column>
          <el-table-column
            prop="discount_coupon_amt"
            label="优惠券优惠合计(元)"
          >
          </el-table-column>
          <el-table-column prop="refund_amt" label="退款(元)">
          </el-table-column>
          <el-table-column prop="order_count" label="笔数"> </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="item">
      <div class="title">优惠券使用汇总</div>
      <div class="table">
        <el-table
          :data="couponSummary"
          border
          style="width: 100%; height: 100%"
        >
          <el-table-column prop="couponType" label="优惠券类型">
          </el-table-column>
          <el-table-column prop="couponAmt" label="优惠券优惠金额(元)">
          </el-table-column>
          <el-table-column prop="count" label="优惠券使用数量（张）">
          </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="item">
      <div class="title">优惠-按油品汇总</div>
      <div class="table">
        <el-table
          :data="oilsummary"
          border
          style="width: 100%; height: 100%"
        >
          <el-table-column prop="oil_name" label="油品">
          </el-table-column>
          <el-table-column prop="discount_coupon_amt" label="优惠券优惠(元)">
          </el-table-column>
          <el-table-column prop="consume_discount_amt" label="消费立减优惠(元)">
          </el-table-column>
          <el-table-column prop="recharge_discount_amt" label="充值立减优惠（元）">
          </el-table-column>
          <el-table-column prop="all_discount" label="合计">
          </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="item">
      <div class="title">充值-员工方式汇总</div>
      <div class="table">
        <el-table
          :data="changeClassSettlement4User"
          border
          style="width: 100%; height: 100%"
        >
          <el-table-column prop="oilPersonnelName" label="账号">
            <!-- <template slot-scope="scope">
              {{
                scope.row.oilPersonnelId ? scope.row.oilPersonnelName : "其他"
              }}
            </template> -->
          </el-table-column>
          <!-- <el-table-column prop="oil_name" label="油品"> </el-table-column> -->
          <el-table-column prop="amt" label="应收(元)"> </el-table-column>
          <el-table-column prop="amt" label="实收(元)"> </el-table-column>
          <el-table-column label="优惠(元)">0 </el-table-column>
          <el-table-column prop="orderCount" label="笔数"> </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="item">
      <div class="title">充值-汇总</div>
      <div class="table">
        <el-table :data="cardSum" border style="width: 100%; height: 100%">
          <el-table-column
            prop="payType"
            label="充值类型"
            :formatter="formatterCardSumPaytype"
          >
          </el-table-column>
          <el-table-column prop="amt" label="实收(元)">
            <template slot-scope="scope">
              {{ scope.row.amt ? scope.row.amt : 0 }}
            </template>
          </el-table-column>
          <el-table-column prop="giveAmt" label="赠送(元)">
            <template slot-scope="scope">
              {{ scope.row.giveAmt ? scope.row.giveAmt : 0 }}
            </template>
          </el-table-column>
          <el-table-column prop="orderCount" label="笔数">
            <template slot-scope="scope">
              {{ scope.row.orderCount ? scope.row.orderCount : 0 }}
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="item">
      <div class="title">会员卡-消费汇总</div>
      <div class="table">
        <el-table :data="dzkSum" border style="width: 100%; height: 100%">
          <el-table-column
            prop="payType"
            :formatter="formatterDzkPayType"
            label="消费类型"
          >
          </el-table-column>
          <el-table-column prop="amt" label="实收(元)"> </el-table-column>
          <el-table-column prop="giveAmt" label="优惠(元)"> </el-table-column>
          <el-table-column prop="orderCount" label="笔数"> </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="item">
      <div class="title">退款-汇总</div>
      <div class="table">
        <el-table :data="refundSum" border style="width: 100%; height: 100%">
          <el-table-column
            prop="payType"
            label="退款类型"
            :formatter="formatterRefundPay"
          >
          </el-table-column>
          <el-table-column prop="refundAmt" label="金额(元)"> </el-table-column>
          <el-table-column prop="orderCount" label="笔数"> </el-table-column>
        </el-table>
      </div>
    </div>
    <p
      v-show="summaryData.summary && summaryData.summary.isShowCommission === 1"
    >
      通道费:银行卡通道费合计
      {{ summaryData.summary ? summaryData.summary.yhkCommission : 0 }}
      元, 扫码支付通道费合计
      {{ summaryData.summary ? summaryData.summary.otherCommission : 0 }}
      元,总通道费合计
      {{ summaryData.summary ? summaryData.summary.allCommission : 0 }}
      元
    </p>

    <!--
    <div class="item">
      <div class="title">非油品汇总</div>
      <div class="table">
        <el-table :data="table2" border style="width: 100%; height: 100%">
          <el-table-column prop="q1" label="合计金额"> </el-table-column>
          <el-table-column prop="q2" label="合计优惠"> </el-table-column>
          <el-table-column prop="q3" label="合计应收款"> </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="item">
      <div class="title">员工加油汇总</div>
      <div class="table">
        <el-table :data="table2" border style="width: 100%; height: 100%">
          <el-table-column prop="q1" label="员工"> </el-table-column>
          <el-table-column prop="q2" label="油品"> </el-table-column>
          <el-table-column prop="q3" label="油枪"> </el-table-column>
          <el-table-column prop="q4" label="加油量"> </el-table-column>
          <el-table-column prop="q5" label="分类应收款"> </el-table-column>
        </el-table>
      </div>
    </div>
    -->
    <!--
    <div class="item">
      <div class="title">活动优惠汇总</div>
      <div class="table">
        <el-table :data="queryGroupByActivity" border style="width: 100%; height: 100%">
        <el-table-column prop="class_no" label="班结号"> </el-table-column>
          <el-table-column prop="order_count" label="订单数量"> </el-table-column>
          <el-table-column prop="discount_amt" label="优惠金额"> </el-table-column>
        </el-table>
      </div>
    </div> -->
    <!--
    <div class="item">
      <div class="title">收款分类汇总</div>
      <div class="table">
        <el-table :data="table2" border style="width: 100%; height: 100%">
          <el-table-column prop="q1" label="收款方式"> </el-table-column>
          <el-table-column prop="q2" label="实收合计"> </el-table-column>
          <el-table-column prop="q3" label="退款合计"> </el-table-column>
          <el-table-column prop="q4" label="优惠合计"> </el-table-column>
          <el-table-column prop="q5" label="加总合计"> </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="item">
      <div class="title">积分商城收款分类汇总</div>
      <div class="table">
        <el-table :data="table2" border style="width: 100%; height: 100%">
          <el-table-column prop="q1" label="收款方式"> </el-table-column>
          <el-table-column prop="q2" label="实收合计"> </el-table-column>
          <el-table-column prop="q3" label="优惠合计"> </el-table-column>
          <el-table-column prop="q4" label="使用积分"> </el-table-column>
          <el-table-column prop="q5" label="订单合计"> </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="item">
      <div class="title">自定义金额充值</div>
      <div class="table">
        <el-table :data="table2" border style="width: 100%; height: 100%">
          <el-table-column prop="q1" label="微信"> </el-table-column>
          <el-table-column prop="q2" label="支付宝"> </el-table-column>
          <el-table-column prop="q3" label="现金"> </el-table-column>
          <el-table-column prop="q4" label="使用积分"> </el-table-column>
          <el-table-column prop="q5" label="银行卡额"> </el-table-column>
        </el-table>
      </div>
    </div>
    -->
    <div class="last" v-if="!!querySummaryByClassNo[0]">
      <div>收银员：{{ querySummaryByClassNo[0].createName }}</div>
      <div>
        班结时间：{{ querySummaryByClassNo[0].classStartTime }}-{{
          querySummaryByClassNo[0].classEndTime
        }}
      </div>
    </div>

    <div>
      <el-input
        maxlength="100"
        type="textarea"
        :rows="3"
        placeholder="请输入备注"
        v-model="note"
      >
      </el-input>
    </div>

    <div style="margin: 10px 0; text-align: center">
      <!-- <button type="default">确认班结</button> -->
      <el-button
        @click="goSettlement"
        type="primary"
        size="medium"
        style="width: 300px"
        :disabled="canSummary"
        :loading="loading"
        >确认班结</el-button
      >
    </div>
  </div>
</template>

<script>
import {
  getSettlementInfo,
  getIntoSettlement,
  getGoSettlement,
} from "@/api/settlement";
import { sysDeptDemoList } from "@/api/label/label";
import { getStationList } from "@/api/dept";
export default {
  data() {
    return {
      querySummaryByClassNo: [],
      queryGroupByActivity: [],
      // classSettlementOilmachines: [], //消费-油机汇总
      queryGroupByOil: [], // 消费-油品汇总
      queryGroupByOilGun: [], // 消费-油枪汇总
      queryGroupByPayType: [], //  消费-支付方式汇总
      changeClassSettlement4User: [], //充值-支付方式汇总
      queryGroupByEmployees: [], // 消费-员工方式汇总
      couponSummary: [], //优惠卷使用汇总
      oilsummary:[],//油品汇总
      cardSum: [], // 充值-汇总
      dzkSum: [],
      refundSum: [], // 退款-汇总
      loading: false,

      table1: [
        // {
        //     title1: "消费合计应收（不含充值）：",
        //     amount1: "",
        //     title2: "短款：",
        //     amount2: "",
        //   },
        //   {
        //     title1: "消费合计实收（不含充值）：",
        //     amount1: "",
        //     title2: "优惠券合计金额：",
        //     amount2: "",
        //   },
        //   {
        //     title1: "充值实收合计金额：",
        //     amount1: "",
        //     title2: "立减合计金额：",
        //     amount2: "",
        //   },
        //   {
        //     title1: "客户退款合计金额：",
        //     amount1: "",
        //     title2: "回罐合计金额：",
        //     amount2: "",
        //   }
        {
          title1: "消费合计应收(元):",
          amount1: "",
          title2: "消费合计实收(元):",
          amount2: "",
        },
        {
          title1: "消费合计优惠(元):",
          amount1: "",
          title2: "消费赠送总金额(元):",
          amount2: "",
        },
        {
          title1: "消费合计退款(元):",
          amount1: "",
          title2: "优惠券核销金额(元):",
          amount2: "",
        },
        {
          title1: "消费赠送返利金(元):",
          amount1: "",
          title2: "消费使用返利金(元):",
          amount2: "",
        },
        {
          title1: "充值合计实收(元):",
          amount1: "",
          title2: "充值立减优惠(元):",
          amount2: "",
        },
        {
          title1: "充值合计赠送(元):",
          amount1: "",
          title2: "充值合计退款(元):",
          amount2: "",
        },
        {
          title1: "秒杀订单金额(元):",
          amount1: "",
          title2: "聚合支付消费合计(元):",
          amount2: "",
        },
        {
          title1: "到账总金额(元):",
          amount1: "",
        },
        // {
        //   title1: "优惠券核销金额(元):",
        //   amount1: "",
        // },
      ],

      table2: [
        {
          q1: "11",
          q2: "12",
          q3: "13",
          q4: "14",
          q5: "15",
        },
      ],
      classEndTime: "",
      stationList: [], // 下拉框的油站列表
      stationId: "", // 要班结的油站id
      summaryData: {},
      note: "", // 备注
      lastBanjieTime: "", // 油站上一次最后班结的时间
      createEndTime: "", // 当前次班结结束时间
      isOnlyOneStation: false, // 当前油企是否只有一个油站
      isStationAccount: false, // 当前登录的账号是否是油站账号
      updateTimeLoading: false,
    };
  },
  created() {
    this.getStationList();

    // // 判断当前是否是油站账号登录 ： 如果油站账号登录，直接默认请求对应的班结数据
    // const authArrtemp = this.$store.state.user.roles;
    // if (authArrtemp.length && (authArrtemp.includes("2") ||authArrtemp.includes("3") )) {
    //   console.log("油站账号");
    //   this.isStationAccount = true;
    //   this.staionChange(this.$store.state.user.stationId); // 获取班结数据
    //   return
    // } else {
    //   console.log("不是油站账号");
    // }
  },
  computed: {
    canSummary() {
      return !this.stationId;
    },
  },
  mounted() {
    // this.staionChange();
  },
  methods: {
    staionChange(stationId) {
      console.log(222);
      if (!stationId) {
        return;
      }
      console.log(123, this.stationList);
      this.updateTimeLoading = true;
      getIntoSettlement({
        stationId: stationId,
      }).then((res) => {
        console.log("查询班结信息", res.data.data);
        this.updateTimeLoading = false;

        this.lastBanjieTime = res.data.startTime || "首次班结开始时间为空"; // 上一次班结时间
        this.createEndTime = res.data.createEndTime; // 本次班结的结束时间

        this.queryGroupByOil = res.data.data.queryGroupByOil; // 消费-油品汇总
        // this.classSettlementOilmachines = res.data.data.classSettlementOilmachines // 消费-油机汇总
        this.queryGroupByOilGun = res.data.data.queryGroupByOilGun; // 消费-油枪汇总
        this.queryGroupByPayType = res.data.data.queryGroupByPayType; //  消费-支付方式汇总
        this.queryGroupByEmployees = res.data.data.listDetail4User; // 消费-员工方式汇总
        this.couponSummary = res.data.summary.couponSummary; //优惠卷使用汇总
        this.oilsummary=res.data.data.queryGroupDiscountByOil;//油品优惠汇总
        this.changeClassSettlement4User =
          res.data.data.changeClassSettlement4User; //充值-员工方式汇总
        this.cardSum = res.data.summary.transactionSummary; //  充值-汇总
        this.dzkSum = res.data.data.queryGroupByRecharge; // 电子卡-交易汇总
        this.queryGroupByActivity = res.data.queryGroupByActivity; // 优惠活动
        this.refundSum = res.data.summary.refundSummary; // 退款-汇总
        console.log(
          res.data.summary.refundSummary,
          "res.data.summary.refundSummary"
        );
        // 班结对账汇总
        this.summaryData = res.data;
        // table1
        this.table1[0].amount1 = this.summaryData.summary.receivableAmt || 0; // 消费合计应收
        this.table1[0].amount2 = this.summaryData.summary.amt || 0; // 消费合计应收
        this.table1[1].amount1 = this.summaryData.summary.totalDiscountAmt; // 消费合计优惠
        // this.table1[1].amount2 = this.summaryData.summary.consumptionRefundAmt; // 消费合计退款
        this.table1[1].amount2 = this.summaryData.summary.presentAmount || 0; // 消费赠送总金额
        this.table1[2].amount1 =this.summaryData.summary.consumptionRefundAmt || 0; // 消费合计退款
        // this.table1[2].amount1 =
        //   this.summaryData.summary.actualRechargeReceivedAmt || 0; // 充值实收合计
        this.table1[2].amount2 = this.summaryData.summary.killCouponAmt || 0; //  核销核销金额
        // this.table1[2].amount2 =
        //   this.summaryData.summary.totalRechargeWithdrawalAmount; // 充值合计提现
        this.table1[3].amount1 =this.summaryData.summary.giftReturnCash || 0; // 消费赠送返利金
        this.table1[3].amount2 =this.summaryData.summary.returnCashAmt || 0; // 消费使用返利金

        this.table1[4].amount1 =this.summaryData.summary.actualRechargeReceivedAmt || 0; // 充值合计实收
        // this.table1[3].amount1 = this.summaryData.summary.totalPresentAmt || 0; // 充值合计赠送
        this.table1[4].amount2 =this.summaryData.summary.rechargeReduceDiscounts || 0; // 充值立减优惠
        // this.table1[3].amount2 =
        //   this.summaryData.summary.totalRechargeRefundAmt; // 充值合计退款
        this.table1[5].amount1 = this.summaryData.summary.totalPresentAmt || 0; // 充值合计赠送
        // this.table1[4].amount1 = this.summaryData.summary.allAmt; // 到账总金额
        this.table1[5].amount2 =this.summaryData.summary.totalRechargeRefundAmt || 0; // 提现总金额
        this.table1[6].amount1 = this.summaryData.summary.saleActivityAmt || 0; // 秒杀订单金额
        this.table1[6].amount2 =this.summaryData.summary.aggregatedPayment || 0; // 聚合支付
        this.table1[7].amount1 =this.summaryData.summary.totalWithdrawalAmount || 0; // 到账总金额
        // 消费--员工方式  合计
        // const employeesRow = {};
        // employeesRow.oil_personnel_name = "合计";
        // employeesRow.oil_name = "xxxxxx";
        // employeesRow.receivable_amt = "xxxxxx";
        // employeesRow.amt = "xxxxxx";
        // employeesRow.discount_amt = "xxxxxx";
        // employeesRow.discount_coupon_amt = "xxxxxx";
        // employeesRow.refund_amt = "xxxxxx";
        // this.queryGroupByEmployees.push(employeesRow);

        // //  支付方式汇总--合计
        // const sumPayType = {};
        // sumPayType.pay_type = "合计";
        // // sumPayType.pay_type = res.data.querySummaryByClassNo.receivableAmt;
        // sumPayType.amt = res.data.data.querySummaryByClassNo[0]?.amt || 0;
        // sumPayType.refund_amt =
        //   res.data.data.querySummaryByClassNo[0]?.refundAmt || 0;
        // sumPayType.discount_amt =
        //   res.data.data.querySummaryByClassNo[0]?.discountAmt || 0;
        // sumPayType.serviceCharge =
        //   res.data.data.querySummaryByClassNo[0]?.serviceCharge || 0;
        // sumPayType.serviceCharge =
        //   res.data.data.querySummaryByClassNo[0]?.serviceCharge || 0;
        // sumPayType.sumPrice =
        //   res.data.data.querySummaryByClassNo[0]?.sumPrice || 0;
        // sumPayType.discount_coupon_amt =
        //   res.data.data.querySummaryByClassNo[0]?.discountCouponAmt || 0;

        // this.queryGroupByPayType.push(sumPayType); // 追加合计字段

        // // 充值-汇总  添加 合计 cardSum
        // const cardSumRow = {};
        // cardSumRow.payType = "合计";
        // cardSumRow.ss = "----";
        // cardSumRow.tx = "----";
        // cardSumRow.orderCount = "----";
        // this.cardSum.push(cardSumRow);
      });
    },
    // 判断是油企，油站，admin
    // 0:admin   1:油企  2: 油站
    authFn(authArr) {
      console.log(authArr, "角色字段");
      let data = {
        pageSize: 100,
        pageNum: 1,
      };
      if (authArr.length > 0) {
        if (authArr.length >= 1 && authArr.includes("1")) {
          data.enterpriseId = this.presentEnterprise.enterpriseId;
          return data;
        } else if (authArr.length >= 1 && authArr.includes("2")) {
          data.stationId = this.presentSation;
          return data;
        }
      } else {
        return data;
      }
    },

    // 获取油站列表
    getStationList() {
      let data = this.authFn(this.$store.state.user.roles);
      // status 油站的状态 : 1 正常, 0 停用
      data = {
        ...data,
        status: 1,
      };
      getStationList(data).then((res) => {
        this.stationList = res.rows;
        if (res.rows.length <= 1) {
          this.isOnlyOneStation = true;
        }

        // 判断当前是否是油站账号登录 ： 如果油站账号登录，直接默认请求对应的班结数据
        const authArrtemp = this.$store.state.user.roles;
        if (
          authArrtemp.length &&
          (authArrtemp.includes("2") || authArrtemp.includes("3"))
        ) {
          console.log("油站账号");
          this.isStationAccount = true;
          // this.staionChange(this.$store.state.user.stationId); // 获取班结数据
        } else {
          console.log("不是油站账号");
        }
        // 如果是单站，则直接数据回显到下拉框，并请求对应的班结数据
        if (
          res.rows.length === 1 ||
          (authArrtemp.length &&
            (authArrtemp.includes("2") || authArrtemp.includes("3")))
        ) {
          if (this.isStationAccount) {
            this.staionChange(this.$store.state.user.stationId);
            this.stationId = this.$store.state.user.stationId;
          } else if (res.rows.length == 1) {
            this.stationId = res.rows[0].stationId;
            this.staionChange(res.rows[0].stationId);
          }
        }
        // this.stationListTotal = res.total;
        // this.stationList = res.rows;
      });
    },

    // 确认班结
    goSettlement() {
      this.loading = true;
      getGoSettlement({
        classEndTime: this.createEndTime,
        stationId: this.stationId,
        note: this.note,
      }).then((res) => {
        this.loading = false;
        this.$router.replace({
          path: "/banjie/Overview_WorkSummaryRecord",
        });
      });
    },
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
      if (rowIndex % 2 === 0) {
        if (columnIndex === 0) {
          return [1, 2];
        } else if (columnIndex === 1) {
          return [0, 0];
        }
      }
    },

    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      console.log(rowIndex, columnIndex);
      if (columnIndex === 0) {
        if (rowIndex % 2 === 0) {
          return {
            rowspan: 2,
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },
    addclass(row) {
      if (row.columnIndex % 2 === 0) return "cellcss";
    },

    // 格式化支付类型
    formatterPayType(row, column) {
      const types = {
        wx: "微信支付",
        zfb: "支付宝",
        xj: "现金支付",
        dzk: "电子卡支付",
        pos: "POS机支付",
        yzf: "预支付",
        kbzf: "卡包支付",
        yhk: "银行卡支付",
        cdk: "车队卡支付",
        dkq: "实体卡支付",
      };
      if (types[row.pay_type] !== "合计" && !types[row.pay_type]) {
        return row.pay_type;
      } else {
        return row.pay_type !== "合计" ? types[row.pay_type] ?? "" : "合计";
      }
    },

    formatterDzkPayType(row, column) {
      const type = {
        // imp: "手动增加",
        msub: "手动扣减",
        // wx: "微信充值",
        // ref: "充值退款",
        dkq: "实体卡支付",
        dzk: "会员卡支付",
      };
      return type[row.payType] ? type[row.payType] : "会员卡支付";
    },

    // 充值类型
    formatterCardSumPaytype(row) {
      const types = {
        pos: "会员卡-移动支付充值",
        imp: "会员卡-充值手动增加",
        wx: "会员卡-微信充值",
        cjhysd: "超级会员-手动添加",
        cjhyxs: "超级会员-线上添加",
        cdk: "车队卡-后台充值",
        dkqxj: "实体卡-后台充值",
        dkqwxpos: "实体卡-移动支付充值",
      };
      return row.payType !== "合计" ? types[row.payType] ?? "" : "合计";
    },

    // 退款类型
    formatterRefundPay(row) {
      const types = {
        wx: "微信支付-消费退款",
        zfb: "支付宝支付-消费退款",
        pos: "POS机支付-消费退款",
        ref: "会员卡支付-充值退款",
        dzk: "会员卡支付-消费退款",
        cdk: "车队卡支付-消费退款",
        dkq: "实体卡支付-消费退款",
        xj: "现金支付-消费退款",
        sref: "超级会员-退款",
        dkqwxposref: "实体卡-移动支付充值退款",
        msref: "秒杀退款",
        yhk: "银行卡-退款",
      };
      return row.payType !== "合计" ? types[row.payType] ?? "" : "合计";
    },
  },
};
</script>
<style lang="scss">
::v-deep .card-table {
  padding: 10px;
  margin-top: 20px;
  background-color: #f8f8f8;

  .el-button {
    margin: 0 5px 0 0;
  }
}

// 表格样式
::v-deep .el-form-item {
  margin-bottom: 0;

  .el-form-item__label {
    padding: 0;
    margin: 0;
    height: 29px;
    font-weight: 400;
    font-size: 12px;
  }

  .el-button--cyan {
    margin-left: 20px;
  }
}

::v-deep .el-table {
  border: 1px #f8f8f8 solid;
  border-bottom: 1px #dfe6ec solid;
}

::v-deep .is-center {
  border: 1px transparent solid;
  border-bottom: 1px #f8f8f8 solid;
}

.collect {
  padding: 20px;
  width: 100%;
  box-sizing: border-box;

  .item {
    margin-top: 10px;

    .title {
      text-align: center;
      height: 35px;
      line-height: 35px;
      font-size: 16px;
      font-weight: bold;
    }
  }

  .cellcss {
    background-color: #f6f6f6;
  }

  .last {
    background-color: #f2f2f2;
    display: flex;
    justify-content: space-between;
    height: 35px;
    line-height: 35px;
    padding: 0 20px;
    box-sizing: border-box;
    margin-bottom: 20px;
  }
}
</style>
